import os


def modify_first_number(file_path):
    # 读取文件内容
    with open(file_path, 'r') as file:
        lines = file.readlines()

    # 修改每行的第一个数字
    modified_lines = []
    for line in lines:
        parts = line.strip().split()
        if not parts:  # 跳过空行
            continue
        # 修改第一个数字
        if parts[0] == '47':
            parts[0] = '28'
        
        modified_line = ' '.join(parts) + '\n'
        modified_lines.append(modified_line)

    # 将修改后的内容写回文件
    with open(file_path, 'w') as file:
        file.writelines(modified_lines)


def process_directory(directory):
    # 遍历目录下的所有文件
    for filename in os.listdir(directory):
        if filename.endswith('.txt'):
            file_path = os.path.join(directory, filename)
            modify_first_number(file_path)
            print(f"已处理文件: {filename}")


# 指定要处理的目录路径
directory_path = input("请输入要处理的目录路径: ")
process_directory(directory_path)
print("处理完成!")